﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class QuarterPlan_ModifyQuarterPlanAdd : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
    QuarterPlanofManager dllQuarterPlanofManager = new QuarterPlanofManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {
            bind();
        }
    }
    /// <summary>
    /// 绑定
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-3-6</date>
    void bind()
    {
        object[] _value = new object[1];
        _value[0] = Utility.HttpHelp.getParamsInt("_quarterPlanId");
        DataTable _quarterPlan = dllQuarterPlanofManager.get(QuarterPlanofManager.field.QuarterPlanId.ToString(), _value);
        if (_quarterPlan.Rows.Count > 0)
        {
            #region 去除标记
            _quarterPlan.Rows[0]["CompleteTime"] = _quarterPlan.Rows[0]["CompleteTime"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["CompleteTime"] = _quarterPlan.Rows[0]["CompleteTime"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["CompleteTime"] = _quarterPlan.Rows[0]["CompleteTime"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["StartTime"] = _quarterPlan.Rows[0]["StartTime"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["StartTime"] = _quarterPlan.Rows[0]["StartTime"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["StartTime"] = _quarterPlan.Rows[0]["StartTime"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["MasterPeople"] = _quarterPlan.Rows[0]["MasterPeople"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["MasterPeople"] = _quarterPlan.Rows[0]["MasterPeople"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["MasterPeople"] = _quarterPlan.Rows[0]["MasterPeople"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["MasterDepartment"] = _quarterPlan.Rows[0]["MasterDepartment"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["MasterDepartment"] = _quarterPlan.Rows[0]["MasterDepartment"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["MasterDepartment"] = _quarterPlan.Rows[0]["MasterDepartment"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["QuarterPlanSortId"] = _quarterPlan.Rows[0]["QuarterPlanSortId"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["QuarterPlanSortId"] = _quarterPlan.Rows[0]["QuarterPlanSortId"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["QuarterPlanSortId"] = _quarterPlan.Rows[0]["QuarterPlanSortId"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["Remart"] = _quarterPlan.Rows[0]["Remart"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["Remart"] = _quarterPlan.Rows[0]["Remart"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["Remart"] = _quarterPlan.Rows[0]["Remart"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["SlaveDepartment"] = _quarterPlan.Rows[0]["SlaveDepartment"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["SlaveDepartment"] = _quarterPlan.Rows[0]["SlaveDepartment"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["SlaveDepartment"] = _quarterPlan.Rows[0]["SlaveDepartment"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["SlaveDepartmentDuty"] = _quarterPlan.Rows[0]["SlaveDepartmentDuty"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["SlaveDepartmentDuty"] = _quarterPlan.Rows[0]["SlaveDepartmentDuty"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["SlaveDepartmentDuty"] = _quarterPlan.Rows[0]["SlaveDepartmentDuty"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["VerifyPeople"] = _quarterPlan.Rows[0]["VerifyPeople"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["VerifyPeople"] = _quarterPlan.Rows[0]["VerifyPeople"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["VerifyPeople"] = _quarterPlan.Rows[0]["VerifyPeople"].ToString().Replace("amp;", "");

            _quarterPlan.Rows[0]["WorkItem"] = _quarterPlan.Rows[0]["WorkItem"].ToString().Replace("&", "");
            _quarterPlan.Rows[0]["WorkItem"] = _quarterPlan.Rows[0]["WorkItem"].ToString().Replace("nbsp;", "");
            _quarterPlan.Rows[0]["WorkItem"] = _quarterPlan.Rows[0]["WorkItem"].ToString().Replace("amp;", "");

            #endregion
            this.txtCompleteTime.Text = Convert.ToDateTime(_quarterPlan.Rows[0]["CompleteTime"]).ToShortDateString();
            this.txtStartTime.Text = Convert.ToDateTime(_quarterPlan.Rows[0]["StartTime"]).ToShortDateString();            
            this.txtMasterPeople.Value = _quarterPlan.Rows[0]["MasterPeople"].ToString();
            this.txtMasterDepartment.Text = _quarterPlan.Rows[0]["MasterDepartment"].ToString();
            this.txtQuarterPlanSortId.Value = _quarterPlan.Rows[0]["QuarterPlanSortId"].ToString();
            this.txtRemark.Text = _quarterPlan.Rows[0]["Remart"].ToString();
            this.txtSlaveDepartment.Value = _quarterPlan.Rows[0]["SlaveDepartment"].ToString();
            this.txtSlaveDepartmentDuty.Text = _quarterPlan.Rows[0]["SlaveDepartmentDuty"].ToString();
            this.txtEvaluatePeople.Value = _quarterPlan.Rows[0]["EvaluatePeople"].ToString();
            this.txtWorkItem.Text = _quarterPlan.Rows[0]["WorkItem"].ToString();
        }
    }
    /// <summary>
    /// 判断控件值是否为空
    /// </summary>
    /// <returns>空返回0，有值返回1</returns>
    /// <author>gzz</author>
    /// <date>2009-3-19 </date>
    int isNull()
    {
        #region 验证是否为空
        if (this.txtQuarterPlanSortId.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtCompleteTime.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtMasterPeople.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtWorkItem.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtSlaveDepartment.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtSlaveDepartmentDuty.Text.Length < 18 && this.txtSlaveDepartment.Value != "独立完成")
        {
            return 0;
        }
        if (this.txtStartTime.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtEvaluatePeople.Value.Length == 0)
        {
            return 0;
        }
        return 1;
        #endregion
    }

    /// <summary>
    /// 时间验证
    /// </summary>
    bool verifyDate()
    {
        #region 必要验证判断
        //判断完成时间是否大于起始时间

        DateTime _startTime = Convert.ToDateTime(this.txtStartTime.Text.Trim());
        DateTime _endTime = Convert.ToDateTime(this.txtCompleteTime.Text.Trim());
        if (!dllAuthentication.IsEndTimeGreaterThanStartTime(_startTime, _endTime))
        {
            Utility.HttpHelp.alert("完成时间需要大于起始时间", Page);
            return false;
        }


        return true;
        #endregion
    }
    /// <summary>
    /// 修改事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date></date>
    protected void btnModify_Click(object sender, EventArgs e)
    {
        int _isnull = isNull();
        if (_isnull == 0)
        {
            Utility.HttpHelp.alert("请输入完整", Page);
            return;
        }
        else
        {
            if (Convert.ToInt32(this.txtQuarterPlanSortId.Value) == 0)
            {
                Utility.HttpHelp.alert("计划编号只能从1开始！", Page);
                return;
            }
            if (!verifyDate())
            {
                return;
            }
            if (this.txtMasterPeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("责任人不可为多人！", Page);
                return;
            }
            if (this.txtEvaluatePeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("评估人不可为多人！", Page);
                return;
            }
            object[] _value = new object[11];
            _value[0] = Convert.ToDateTime(this.txtCompleteTime.Text);
            _value[1] = this.txtMasterPeople.Value;
            _value[2] = this.txtMasterDepartment.Text;
            _value[3] = Convert.ToInt32(this.txtQuarterPlanSortId.Value);
            _value[4] = this.txtRemark.Text;
            _value[5] = this.txtSlaveDepartment.Value;
            _value[6] = this.txtSlaveDepartmentDuty.Text;
            _value[7] = Convert.ToDateTime(this.txtStartTime.Text);
            _value[8] = this.txtEvaluatePeople.Value;
            _value[9] = this.txtWorkItem.Text;
            _value[10] = Utility.HttpHelp.getParamsInt("_quarterPlanId");
            int result = dllQuarterPlanofManager.editQuartPlanContent(_value);
            if (result == 0)
            {
                Utility.HttpHelp.alert("修改年计划未成功，请重试！", Page);
            }
            else
            {
                int _quarterDate = Utility.HttpHelp.getParamsInt("_quarterDate");
                Utility.HttpHelp.closeWindow("QuarterPlanAdd.aspx?Id=" + _quarterDate, Page);
            }
        }
    }
}
